package assist.service.gwt.impl;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Date;
import java.util.Set;

import java.util.logging.Logger;

import javax.jdo.annotations.NotPersistent;

import assist.datastore.JDODatastore;
import assist.datastore.dao.DAOFactory;
import assist.datastore.dao.GameDAO;
import assist.datastore.dao.PlayerDAO;
import assist.datastore.dao.TeamDAO;
import assist.datastore.parser.NHLEventsCSVParser;
import assist.datastore.parser.NHLGamesCSVParser;
import assist.datastore.parser.NHLPlayerAliasCSVParser;
import assist.datastore.parser.NHLPlayerYearCSVParser;
import assist.datastore.parser.NHLPlayersCSVParser;
import assist.datastore.parser.NHLRostersCSVParser;
import assist.datastore.parser.NHLTeamCSVParser;
import assist.domain.model.EventPlayerOnIce;
import assist.domain.model.PlayerYear;
import assist.domain.model.Event;
import assist.domain.model.Game;
import assist.domain.model.Player;
import assist.domain.model.PlayerAlias;
import assist.domain.model.RosterPlayer;
import assist.domain.model.Stats.Row;
import assist.domain.model.StatsQuery.RowQuery;
import assist.domain.model.Team;
import assist.domain.service.StatsService;
import assist.service.gwt.interfaces.HockeyStatsService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
public class HockeyStatsServiceImpl extends RemoteServiceServlet implements
     HockeyStatsService
{

    private StatsService statsService = new StatsService();
    @Override
    public Row getStatsRow(RowQuery rowQuery)
    {        
        return this.statsService.getStatsRow(rowQuery);
    }
    
    
    
    
    
    
    
    @NotPersistent
    private static final long serialVersionUID = 1L;    
    private static Logger logger = 
        Logger.getLogger(HockeyStatsServiceImpl.class.getName());
    public String helloHockey()
    {
        logger.info("Hello Hockey");
        return "Hello, Hockey Service!";       
    }
  
    
    
    @Override
    public Set<Player> getTeamPlayers(Team team, Date start, Date end)
    {        
        logger.info("Getting the Players for Dates");
        GameDAO gameDao = DAOFactory.getDAOFactory().getGameDAO();
        Collection<Game> games = gameDao.getGames(team, start, end);  
        PlayerDAO playerDao = DAOFactory.getDAOFactory().getPlayerDAO();
        return playerDao.getPlayersInGames(games, team);
        //Get games involving Team, Date.
       
        //Get the Roster Players, and add Players to a Set.
    }
    
    public Set<Player> getTeamPlayers(Team team, Set<Game> games)
    {
        logger.info("Getting the Players for Games");
        PlayerDAO playerDao = DAOFactory.getDAOFactory().getPlayerDAO();
        return playerDao.getPlayersInGames(games, team);        
    }
    



    @Override
    public Set<Team> getTeams()
    {
        logger.info("Getting the Teams.");  
        TeamDAO teamDao = DAOFactory.getDAOFactory().getTeamDAO();
        return teamDao.getCurrentTeams();
    }

    @Override
    public Set<Game> getGames(Team team, Date start, Date end)
    {
        logger.info("Loading Games");  
        GameDAO gameDao = DAOFactory.getDAOFactory().getGameDAO();
        Set<Game> games = gameDao.getGames(team, start, end);
        return games;
    }
}


